import { getActorData } from "@@/apis/video/actor"
import { reactive, ref } from "vue"

export function useTable() {
  const tableData = ref([])
  const searchParams = reactive({
    actorName: ""
  })

  const currentPage = ref(1)
  const pageSize = ref(15)
  const total = ref(0)

  const fetchData = async () => {
    const params = {
      actorName: searchParams.actorName,
      page: currentPage.value,
      pageSize: pageSize.value
    }
    const response: any = await getActorData(params)
    tableData.value = response.data?.list || []
    total.value = response.data.total || 0
  }

  const handlePageChange = (page: number) => {
    currentPage.value = page
    fetchData()
  }

  return {
    tableData,
    searchParams,
    currentPage,
    pageSize,
    total,
    fetchData,
    handlePageChange
  }
}
